package cn.itcast.Rainbow_self_mention.Protocol;

import android.content.Context;
import android.os.Build;

import androidx.annotation.RequiresApi;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

import cn.itcast.Rainbow_self_mention.Dao.UserDao;
import cn.itcast.Rainbow_self_mention.HandlerMessage.CounterMessage;

public class AccountProtocol {
    Map<Integer, Method> methodMap = new HashMap<>();
    CounterMessage counterMessage = new CounterMessage();
    UserDao userDao;
    public AccountProtocol(Context context) throws NoSuchMethodException {
        userDao=new UserDao(context);
        Class<CounterMessage> clazz = CounterMessage.class;
        methodMap.put(4, clazz.getMethod("sentToReset", int.class));
        methodMap.put(3, clazz.getMethod("sentToPersonal", int.class));
        methodMap.put(2, clazz.getMethod("sentToRegistry", int.class));
        methodMap.put(1, clazz.getMethod("sentToLogin", int.class));
    }

    @RequiresApi(api = Build.VERSION_CODES.KITKAT)
    public void match(int s, int args) throws InvocationTargetException, IllegalAccessException {
        Objects.requireNonNull(methodMap.get(s)).invoke(counterMessage, args);

    }


}
